# Maintainer: Peter Budai <peterbudai at hotmail dot com>

_realname=gphoto2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.27
pkgrel=3
pkgdesc="The gphoto2 commandline tool for accessing and controlling digital cameras (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='http://www.gphoto.org/'
license=('GNU')
depends=("${MINGW_PACKAGE_PREFIX}-libgphoto2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libltdl"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-popt")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner
source=("https://github.com/gphoto/gphoto2/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz"
        "01_gphoto_close_before_rename.patch"
	"gphoto2-check-popt.patch")
sha256sums=('2fda6ffe0c7c2da4553801364a8cf6ef60685bd976cbfea24acc0fa142c77199'
            'ca4e431c4f2bca1272a6580ebab7d81a82fa38fad07624cc8c6328b458293b19'
            'fdc32ca1291b42f5d0b5f57ec2de47dfa6201bf45342a202ae86eb1caafd45d0')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/01_gphoto_close_before_rename.patch
  # https://github.com/gphoto/gphoto2/pull/419
  patch -p1 -i ${srcdir}/gphoto2-check-popt.patch

  autoreconf -fiv
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} build-${MSYSTEM}

  cd "${srcdir}/build-${MSYSTEM}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}


package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
